package com.tanjie.blackbean.iot.demo.support;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;

/**
 * @Author tanjie
 * @Date 2022/6/20 下午3:37 周一
 **/
public class MqttUtil {

    public static int qos = 2;

    public static void publish(MqttClient mqttClient, String content, String pubTopic) {
        MqttMessage message = new MqttMessage(content.getBytes());
        message.setQos(qos);
        try {
            mqttClient.publish(pubTopic, message);
        } catch (MqttException e) {
            System.out.println("reason " + e.getReasonCode());
            throw new RuntimeException(e);
        }
    }


}
